package com.allwees.bs.module.oms.rest;

import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.bs.module.oms.req.query.OmsOrderQueryReq;
import com.allwees.bs.module.oms.service.OrderStatisticsService;
import com.allwees.bs.module.oms.vo.HomePageStatisticsVo;
import com.allwees.bs.module.oms.vo.OrderWithStatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单统计
 */
@RestController
@RequestMapping("/backstage/api/oms/order_statistics")
public class OrderStatisticsApi {

    @Autowired
    private OrderStatisticsService orderStatisticsService;

    @GetMapping("/home_page")
    public R homePage(OmsOrderQueryReq req) {
        HomePageStatisticsVo homePageStatisticsDto = new HomePageStatisticsVo()
                .setWaitPayCount(orderStatisticsService.findWaitPayCount(req))//待付款
                .setWaitShipCount(orderStatisticsService.findWaitShipCount(req))//待发货
                .setWaitReviewCount(orderStatisticsService.findWaitReviewCount(req))//待评价
                .setWaitRefundedCount(orderStatisticsService.findRefundedCount(req))//已退款
                //.setWaitShipCount(orderStatisticsService.findWaitShipCount(req))

                .setYesterdayDealAmt(orderStatisticsService.findYesterdayDealAmt(req))//昨日成交
                .setTodayDealAmt(orderStatisticsService.findTodayDealAmt(req))//今日成交
                .setTotalDealAmt(orderStatisticsService.findTotalDealAmt(req))//累计成交
                .setTodayRefundedAmt(orderStatisticsService.findRefundedDealAmt(req));//今日退款
        return R.ok(homePageStatisticsDto);
    }

    @GetMapping("/with_stat")
    public R withStat(OmsOrderQueryReq req) {
        List<OrderWithStatVo> withStats = orderStatisticsService.findWithStat(req);
        return R.ok(withStats);
    }
}
